package com.aizhixin.lab.course.course.controller;

import com.aizhixin.lab.account.dto.AccountDTO;
import com.aizhixin.lab.account.service.AccountService;
import com.aizhixin.lab.common.core.ApiReturnConstants;
import com.aizhixin.lab.common.utils.TokenUtil;
import com.aizhixin.lab.course.course.domain.CourseChapterDomain;
import com.aizhixin.lab.course.course.service.StuLikeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/v1/course/student/like")
@Api(value = "学生点赞相关API")
public class StuLikeController {
    @Autowired
    private AccountService accountService;
    @Autowired
    private StuLikeService stuLikeService;

    @RequestMapping(value = "/teacherLike", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(httpMethod = "GET", value = "课程老师点赞", response = Void.class, notes = "课程老师点赞<br>@author lwq")
    public ResponseEntity<?> teacherLike(@RequestHeader("Authorization") String token,
                                             @ApiParam(value = "courseId", required = true) @RequestParam(value = "courseId", required = true) String courseId,
                                             @RequestParam(value = "teacherId",required = true) Long teacherId) {
        Map<String,Object> result=new HashMap<>();
        AccountDTO account = accountService.getUserByToken(token);
        if (account == null) {
            return new ResponseEntity<Object>(TokenUtil.tokenValid(), HttpStatus.UNAUTHORIZED);
        }
        stuLikeService.teacherLike(courseId,teacherId,account.getId());
        result.put(ApiReturnConstants.SUCCESS,true);

        return new ResponseEntity(result, HttpStatus.OK);
    }
    @RequestMapping(value = "/courseLike", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(httpMethod = "GET", value = "课程点赞", response = Void.class, notes = "课程点赞<br>@author lwq")
    public ResponseEntity<?> courseLike(@RequestHeader("Authorization") String token,
                                             @ApiParam(value = "courseId", required = true) @RequestParam(value = "courseId", required = true) String courseId) {
        Map<String,Object> result=new HashMap<>();
        AccountDTO account = accountService.getUserByToken(token);
        if (account == null) {
            return new ResponseEntity<Object>(TokenUtil.tokenValid(), HttpStatus.UNAUTHORIZED);
        }
        stuLikeService.courseLike(courseId,account.getId());
        result.put(ApiReturnConstants.SUCCESS,true);

        return new ResponseEntity(result, HttpStatus.OK);
    }
    @RequestMapping(value = "/chapterLike", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(httpMethod = "GET", value = "章节点赞", response = Void.class, notes = "章节点赞<br>@author lwq")
    public ResponseEntity<?> chapterLike(@RequestHeader("Authorization") String token,
                                             @ApiParam(value = "chapterId", required = true) @RequestParam(value = "chapterId", required = true) Long chapterId) {
        Map<String,Object> result=new HashMap<>();
        AccountDTO account = accountService.getUserByToken(token);
        if (account == null) {
            return new ResponseEntity<Object>(TokenUtil.tokenValid(), HttpStatus.UNAUTHORIZED);
        }
        stuLikeService.chapterLike(chapterId,account.getId());
        result.put(ApiReturnConstants.SUCCESS,true);

        return new ResponseEntity(result, HttpStatus.OK);
    }
}
